﻿using System;
using System.Windows.Forms;
using Infrastructure;
using PresentationNamespace;

namespace WinClient
{
    public partial class AreaConverterWin : Form, IView
    {
        public AreaConverterWin(int loggerType = 0)
        {
            InitializeComponent();
            if (loggerType == 0)
            {
                new Presenter(this, new TxtLogger());
                IsHtmlLoggerSelected = false;
                IsTxtLoggerSelected = true;
            }
            else
            {
                new Presenter(this, new HtmlLogger());
                IsHtmlLoggerSelected = true;
                IsTxtLoggerSelected = false;
            }
        }

        public string KnownValue
        {
            get { return knownValue.Text; }
        }

        public string KnownMeasure
        {
            get { return knownMeasureType.Text; }
        }

        public string WantedMeasure
        {
            get { return wantedMeasureType.Text; }
        }

        public string WantedValue
        {
            set { wantedValue.Text = value; }
        }

        public string ErrorMessage
        {
            get { return errorMessage.Text; }
            set { errorMessage.Text = value; }
        }

        public object[] MeasureTypes
        {
            set
            {
                knownMeasureType.Items.AddRange(value);
                wantedMeasureType.Items.AddRange(value);
            }
        }

        public string[] LogText 
        {
            set
            {
                logText.Lines = value;
            } 
        }

        public bool IsTxtLoggerSelected 
        {
            get
            {
                return txtLogSelected.Checked;
            }
            set 
            {
                txtLogSelected.Checked = value;
            }
        }

        public bool IsHtmlLoggerSelected
        {
            get
            {
                return htmlLogSelected.Checked;
            }
            set
            {
                htmlLogSelected.Checked = value;
            }
        }

        public string LogFileName 
        {
            get { return logFileName.Text; }
        }

        public event Action OnConvertClick;
        public event Action OnSaveLogAsTxtClick;
        public event Action OnShowLogAsTxtClick;
        public event Action OnSaveLogAsHtmlClick;
        public event Action OnShowLogAsHtmlClick;
        public event Action LoggerTypeChanged;
        
        public ILogger CreateTxtLogger()
        {
            return new TxtLogger();
        }

        public ILogger CreateHtmlLogger()
        {
            return new HtmlLogger();
        }

        private void convertButton_Click(object sender, EventArgs e)
        {
            OnConvertClick();
        }

        private void saveAsTxtButton_Click(object sender, EventArgs e)
        {
            OnSaveLogAsTxtClick();
        }

        private void showAsTxtButton_Click(object sender, EventArgs e)
        {
            OnShowLogAsTxtClick();    
        }

        private void showAsHtmlButton_Click(object sender, EventArgs e)
        {
            OnShowLogAsHtmlClick();
        }

        private void saveLogHtml_Click(object sender, EventArgs e)
        {
            OnSaveLogAsHtmlClick();
        }

        private void txtLogSelected_CheckedChanged(object sender, EventArgs e)
        {
            LoggerTypeChanged();
        }
    }
}
